package com.ruoyi.mp.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.db.domain.system.MpClient;
import com.ruoyi.db.domain.web.MpClientAddress;
import com.ruoyi.mp.annotion.Login;
import com.ruoyi.mp.annotion.LoginUser;
import com.ruoyi.mp.service.IMpClientAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【用户收货地址】Controller
 * 
 * @author ruoyi
 * @date 2022-07-26
 */
@Api(value = "【用户收货地址】",tags ="【用户收货地址】")
@RestController
@RequestMapping("/smp/address")
public class MpClientAddressController extends BaseController
{
    private static Logger log = LoggerFactory.getLogger(MpClientAddressController.class);
    @Autowired
    private IMpClientAddressService mpClientAddressService;

    /**
     * 查询【用户收货地址】列表
     */
    @Login
    @ApiOperation(value = "查询【用户收货地址】列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientAddress",value="【用户收货地址】",paramType="form")
    })
    @GetMapping("/list")
    public TableDataInfo list(MpClientAddress mpClientAddress, @LoginUser MpClient client)
    {
        try {
            startPage();
            mpClientAddress.setClientId(client.getClientId());
            List<MpClientAddress> list = mpClientAddressService.selectMpClientAddressList(mpClientAddress);
            return getDataTable(list);
        }catch (Exception e){
            log.error("【用户收货地址】发生异常",e);
        }
        return null;
    }


    /**
     * 获取【用户收货地址】详细信息
     */
    @Login
    @ApiOperation(value = "获取【用户收货地址】详细信息")
    @ApiImplicitParam(name="addressId",value="【用户收货地址】")
    @GetMapping(value = "/{addressId}")
    public AjaxResult getInfo(@PathVariable("addressId") Long addressId)
    {
        try {
            return AjaxResult.success(mpClientAddressService.selectMpClientAddressByAddressId(addressId));
        }catch (Exception e){
            log.error("【用户收货地址】发生异常",e);
        }
        return AjaxResult.error("【用户收货地址】异常");
    }

    /**
     * 新增【用户收货地址】
     */
    @Login
    @ApiOperation(value = "新增【用户收货地址】")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientAddress",value="【用户收货地址】",dataType="MpClientAddress")
    })
    @PostMapping
    public AjaxResult add(@RequestBody MpClientAddress mpClientAddress,@LoginUser MpClient client)
    {
        try {
            mpClientAddress.setClientId(client.getClientId());
            int i=mpClientAddressService.insertMpClientAddress(mpClientAddress);
            return toAjax(i);
        }catch (Exception e){
            log.error("新增【用户收货地址】发生异常",e);
        }
        return AjaxResult.error("【用户收货地址】异常");
    }

    /**
     * 修改【用户收货地址】
     */
    @Login
    @ApiOperation(value = "修改【用户收货地址】")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientAddress",value="【用户收货地址】",dataType="MpClientAddress")
    })
    @Log(title = "【用户收货地址】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MpClientAddress mpClientAddress,@LoginUser MpClient client)
    {
        try {
            mpClientAddress.setClientId(client.getClientId());
            int i=mpClientAddressService.updateMpClientAddress(mpClientAddress);
            return toAjax(i);
        }catch (Exception e){
            log.error("修改【用户收货地址】发生异常",e);
        }
        return AjaxResult.error("【用户收货地址】异常");
    }
}
